﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;               //数据库头文件
using System.Data.SqlClient;    //数据库头文件
using System.Data.Sql;         //数据库头文件
using DATA_operate_;          //自定义数据库操作类引用

public partial class design_page_admin_Default : System.Web.UI.Page
{
    DATA_operate data_operate_in_admin = new DATA_operate();   //创建数据库操作类对象
 
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void GridView_admin_Command(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "delete_row")
        {
            int SelectedRowIndex = Convert.ToInt32(e.CommandArgument.ToString());
        string str_condition_info = this.GridView_admin.DataKeys[SelectedRowIndex].Value.ToString();     //获得主表字段
        data_operate_in_admin.datadelete("_admin", "_Aid", str_condition_info);
        Response.Redirect(Request.RawUrl);
        }
    }
    protected void GridView_teacher_Command(object sender, GridViewCommandEventArgs e)
    {
      
        if (e.CommandName == "teacher_delete")
        {
            int SelectedRowIndex = Convert.ToInt32(e.CommandArgument.ToString());
            string str_condition_info = this.GridView_teacher.DataKeys[SelectedRowIndex].Value.ToString();     //获得主表字段


            /*
             * delete from _class_homework where _Hid in (select _mHid from _main_homework where _mHTid='1123012010096')
               delete from _student_homework where _Hid in (select _mHid from _main_homework where _mHTid='1123012010096')
               delete from _main_homework where _mHTid='1123012010096'
               delete from _teacher_class where _Tid = '1123012010096'
               delete from _teacher where _Tid = '1123012010096'
             */
            string sql1 = @"delete from _class_homework where _Hid in (select _mHid from _main_homework where _mHTid='" + str_condition_info + @"')
               delete from _student_homework where _Hid in (select _mHid from _main_homework where _mHTid='" + str_condition_info + @"')
               delete from _main_homework where _mHTid='" + str_condition_info + @"'
               delete from _teacher_class where _Tid = '" + str_condition_info + @"'
               delete from _teacher where _Tid = '" + str_condition_info + @"'";


            if (data_operate_in_admin.sqlcmd(sql1).ExecuteNonQuery() > 0)
            {
                Response.Redirect(Request.RawUrl);
            }
            else
            {
                Page.ClientScript.RegisterStartupScript(this.GetType(), "right", "window.alert('删除失败');", true);

            }
             
            /*
            string sql2 = "delete from _student_homework where _Hid in (select _mHid from _main_homework where _mHTid='" + str_condition_info + "')";
          //  string sql3 = "delete from _main_homework where _mHTid='" + str_condition_info + "'";
          //  string sql4 = "delete from _teacher_class where _Tid = '" + str_condition_info + "'";
          //  string sql5 = "delete from _teacher_class where _Tid = '" + str_condition_info + "'";
        //    data_operate_in_admin.sqlcmd(sql1);
        //    data_operate_in_admin.sqlcmd(sql2);
           // data_operate_in_admin.sqlcmd(sql3);
          //  data_operate_in_admin.sqlcmd(sql4);
          //  data_operate_in_admin.sqlcmd(sql5);
        
      //    data_operate_in_admin.datadelete("_main_homework", "_mHTid", str_condition_info);
      //    data_operate_in_admin.datadelete("_teacher_class", "_Tid", str_condition_info);
       //    data_operate_in_admin.datadelete("_teacher", "_Tid", str_condition_info);
             * 
             * 
             * 
             */



            
        }
    }
    protected void GridView_student_Command(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "student_delete")
        {
            int SelectedRowIndex = Convert.ToInt32(e.CommandArgument.ToString());
            string str_condition_info = this.GridView_student.DataKeys[SelectedRowIndex].Value.ToString();     //获得主表字段
            data_operate_in_admin.datadelete("_student_homework", "_Sid", str_condition_info);
            data_operate_in_admin.datadelete("_student", "_Sid", str_condition_info);
            Response.Redirect(Request.RawUrl);
        }
    }
}